﻿using AduSkin.Controls.Metro;
using GrabFieldr.Models.Interface;
using GrabFieldr.ViewModels;
using NewDeMo.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace NewDeMo.Views
{
    /// <summary>
    /// HomePage.xaml 的交互逻辑
    /// </summary>
    public partial class HomePage : UserControl
    {
        IMachineModel machineModel;
        IRegionManager regionManger;
        public HomePage(IMachineModel machineModel, IRegionManager region)
        {
            this.machineModel = machineModel;
            this.regionManger = region;
            this.DataContext = new HomePageViewModel(machineModel, region);
            InitializeComponent();
            UIInit();
        }

        public HomePage()
        {
            InitializeComponent();
            UIInit();
        }

        void UIInit()
        {
            //UI初始化代码
            int WeekIndex = (int)DateTime.Now.DayOfWeek;
            string[] dayNamesChinese = {  "星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日" };
            string[] TimeSelectWeekend = { "10:00-12:00", "14:00-16:00", "16:30-18:30", "19:30-21:30" };
            string[] TimeSelectWork = { "17:30-19:30", "19.30-21:30" };
            string[] FieldSelect = { "1号场", "2号场"};
            if (WeekIndex > 4 || WeekIndex == 0)
            {
                //周末
                for (int i = 0; i < 2; i++)
                {
                    //btns[i].IsEnabled = false;
                    //运动日期选择按钮
                    AduRadioButton SportDate = new AduRadioButton();
                    SportDate.Content = dayNamesChinese[i + 5];
                    SportDate.Tag = i;
                    SportDate.Checked += SportDate_Checked;
                    Grid.SetRow(SportDate, i);
                    Grid.SetColumn(SportDate, 0);
                    // 将按钮添加到Grid的Children集合中
                    SportDateGrid.Children.Add(SportDate);
                }
                //AduFormLable TimeForm = new AduFormLable();
                //AduComboBox TimeCombox = new AduComboBox();  
                //AduFormLable FieldForm = new AduFormLable();
                //AduComboBox FieldCombox = new AduComboBox();
                //TimeForm.Content = "时间段";
                //FieldForm.Content = "场地";
                //TimeCombox.Items.Add(TimeSelectWeekend);
                //FieldCombox.Items.Add(FieldSelect);

                //Grid.SetRow(TimeForm, 0);
                //Grid.SetColumn(TimeForm, 1);
                //Grid.SetRow(TimeCombox, 0);
                //Grid.SetColumn(TimeCombox, 2);
                //Grid.SetRow(FieldForm, 0);
                //Grid.SetColumn(FieldForm,3);
                //Grid.SetRow(FieldCombox, 0);
                //Grid.SetColumn(FieldCombox, 4);

                //TimeFieldGrid.Children.Add(TimeForm);
                //TimeFieldGrid.Children.Add(FieldForm);
                //TimeFieldGrid.Children.Add(TimeCombox);
                //TimeFieldGrid.Children.Add(FieldCombox);
            }
            else
            {
                for (int i = 0; i < 5; i++)
                {
                    //btns[i].IsEnabled = false;
                    //运动日期选择按钮
                    AduRadioButton SportDate = new AduRadioButton();
                    SportDate.Content = dayNamesChinese[i];
                    SportDate.Tag = i;
                    SportDate.Checked += SportDate_Checked;
                    Grid.SetRow(SportDate, i);
                    SportDateGrid.Children.Add(SportDate);
                }
            }
        }

        // 处理运动日期选择按钮的Checked事件
        private void SportDate_Checked(object sender, RoutedEventArgs e)
        {
            // 获取触发事件的对象[2](@ref)
            AduRadioButton radioButton = (AduRadioButton)sender;
            if (radioButton.IsChecked==true) // 或者使用 IsChecked 属性，取决于AduRadioButton的实际定义
            {
                //// 获取选中的日期，这里从Tag中取出之前存储的内容
                //string selectedDate = radioButton.Tag?.ToString();
                //// 执行您的业务逻辑，例如更新界面、存储选中状态等
                //MessageBox.Show($"选中日期: {selectedDate}"); // 示例操作

                this.machineModel.SelectedIndex = (int)radioButton.Tag;
            }
        }
    }
}
